//https://leetcode.cn/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/
//字符串转整形
class Solution {

public:

    int myAtoi(string str) {

        long long ret = 0;

        int flag = 0;

        string::iterator it = str.begin();

        while(it != str.end())

        {

            if(*it != ' ')

                break;

            else

                it++;

        }



        if(*it == '-' || *it == '+')

        {

            flag = *it - '+';

            it++;

        }



        while(it != str.end() && *it >= '0' && *it <= '9')

        {

            ret *= 10;

            ret += *it - '0';

            if(ret > 2147483648)

                break;

            it++;

        }



        if(flag != 0)

            ret = -ret;



        if(ret > 2147483647)

            ret = 2147483647;

        else if(ret < -2147483648)

            ret = -2147483648;



        return ret;

    }

};